package com.shushan.util;

/**
 * @ClassName: SolarYear
 * @Desciption: //TODO
 * @author: yichaohua
 * @date: 2018-09-14
 */
public class SolarYear {
    private int[] solarMonth = {31,28,31,30,31,30,31,31,30,31,30,31};
    private int temp_total_day;
    private int gc_solar_calendar_year;
    private int gc_solar_calendar_month;
    private int gc_solar_calendar_date;
    private int start_day_of_week;
    /**
     *
     * @param gc_solar_calendar_year 年份
     * @param gc_solar_calendar_month 月份
     * @return 每月第一天是星期几
     */
    public int getSolarDayDate(int gc_solar_calendar_year,int gc_solar_calendar_month){
        int temp01;
        start_day_of_week = 2;
        temp_total_day = 0;
        int calculate_temp = 1;

        if(gc_solar_calendar_year>99){
            start_day_of_week =4;
            calculate_temp = 100;
        }
        for(temp01 = calculate_temp; temp01<gc_solar_calendar_year; temp01++){
            if(temp01%4 == 0){
                start_day_of_week +=2;temp_total_day +=366;
            }else{
                start_day_of_week +=1;temp_total_day +=365;
            }
        }
        for(temp01 = 1;temp01<gc_solar_calendar_month;temp01++){
            switch(temp01){
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:{
                    start_day_of_week +=3;temp_total_day +=31;
                }break;
                case 2:{
                    if((gc_solar_calendar_year%4 == 0)&&(gc_solar_calendar_year!=200)){
                        start_day_of_week +=1; temp_total_day +=29;
                    }else{
                        start_day_of_week +=0; temp_total_day+=28;
                    }
                }break;
                case 4:
                case 6:
                case 9:
                case 11:{start_day_of_week +=2;temp_total_day +=30;}break;
            }
        }
        start_day_of_week%=7;
//        System.out.println(gc_solar_calendar_year+"年，"+gc_solar_calendar_month+"月,第一天是周"+(start_day_of_week));
        return start_day_of_week;
    }
    /**
     *
     * @param gc_solar_calendar_year 年份
     * @param gc_solar_calendar_month 月份
     * @return 公历y年month-1月的天数
     */
    public int daysOfMonth(int gc_solar_calendar_year,int gc_solar_calendar_month){
        if(gc_solar_calendar_month==1)
            return(((gc_solar_calendar_year%4 == 0) && (gc_solar_calendar_year%100 != 0) || (gc_solar_calendar_year%400 == 0))? 29: 28);
        else
            return(solarMonth[gc_solar_calendar_month]);
    }
}
